import static javax.media.opengl.GL2.GL_QUADS;

/**
 * Extends genericGlObject with square.
 * 
 *       Created 27/apr/2013.
 * @author Pietro Bolognesi matr. 227383
 * @author Giorgio Lazzaretti matr. 220232
 *  
 */
public class GlSquare extends GenericGlObject {
	/**
	 *  Contains the side of the square.
	 */
	protected float l;
	
	/**
	 * Create a new square 
	 *
	 */
	public GlSquare(){
		this.l = 0.2f;
		this.ObjectName = "Square";
		SetObjectColor(1.0f,0.0f,0.0f);
		this.ToDraw = true;
	}

	/**
	 * Set the side of the square.
	 *
	 * @param newL Side.
	 */
	public void SetSquareDim(float newL){this.l = newL;}
	/**
	 * Returns the side of the square.
	 *
	 * @return Side.
	 */
	public float GetSquareDim(){return this.l;} 
	/**
	 * Draw the square.
	 *
	 */
	@Override
	public void DrawObject(){
		if(!this.ToDraw)
			return;
		// ----- Render a quad -----
		// la terza componente essendo 2d non viene utilizzata
		this.gl.glColor3f(this.Red, this.Green, this.Blue);
		this.gl.glBegin(GL_QUADS); 
		this.gl.glVertex3f(-this.l, this.l, 0.0f);
		this.gl.glVertex3f(this.l, this.l, 0.0f);
		this.gl.glVertex3f(this.l, -this.l, 0.0f);
		this.gl.glVertex3f(-this.l, -this.l, 0.0f);
		this.gl.glEnd();
	}
}
